﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SweetWeather
{
    /// <summary>
    /// StartWindow.xaml 的交互逻辑
    /// </summary>
    public partial class StartWindow : Window
    {
        /// <summary>
        /// 关闭子窗体委托
        /// </summary>
        public delegate void CloseThis();
        public StartWindow()
        {
            InitializeComponent();
        }

        public event CloseThis closeTheWindows;
        private void Window_Closed(object sender, EventArgs e)
        {
            closeTheWindows();
        }

        /// <summary>
        /// 重写OnCloseIng，关闭特效
        /// </summary>
        bool _closinganimation = true;
        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = _closinganimation;
            _closinganimation = false;
            base.OnClosing(e);

            System.Windows.Media.Animation.Storyboard sb = new System.Windows.Media.Animation.Storyboard();
            System.Windows.Media.Animation.DoubleAnimation dh = new System.Windows.Media.Animation.DoubleAnimation();
            System.Windows.Media.Animation.DoubleAnimation dw = new System.Windows.Media.Animation.DoubleAnimation();
            System.Windows.Media.Animation.DoubleAnimation dop = new System.Windows.Media.Animation.DoubleAnimation();
            dop.Duration = dh.Duration = dw.Duration = sb.Duration = new Duration(new TimeSpan(0, 0, 2));
            dop.To = dh.To = dw.To = 0;
            System.Windows.Media.Animation.Storyboard.SetTarget(dop, this);
            System.Windows.Media.Animation.Storyboard.SetTarget(dh, this);
            System.Windows.Media.Animation.Storyboard.SetTarget(dw, this);
            System.Windows.Media.Animation.Storyboard.SetTargetProperty(dop, new PropertyPath("Opacity", new object[] { }));
            System.Windows.Media.Animation.Storyboard.SetTargetProperty(dh, new PropertyPath("Height", new object[] { }));
            System.Windows.Media.Animation.Storyboard.SetTargetProperty(dw, new PropertyPath("Width", new object[] { }));
            sb.Children.Add(dh);
            sb.Children.Add(dw);
            sb.Children.Add(dop);

            sb.Completed += (a, b) => { this.Close(); };
            sb.Begin();
        }
    }
}
